/**
 * 控制台员工统计控制器
 */
import tem from './index.html'
import './index.less'
import G2 from 'g2'
import $_fn from '~plugins'
class chartsStaffCtrl {
    constructor($scope) {
    	$scope.fn=function(list){
    		/*var data = [
            { value: 0.35, key: '正常' },
            { value: 0.65, key: '离职' },
        ];*/
       var datas=list.data.consolePieChart.getUserLockedPie
        var nums=0
        var data=[]
	     if(datas && datas.length){
	      	for(var i=0; i<datas.length; i++ ){
		      	nums+=parseInt(datas[i].count)
		      }
		      for(var j=0; j<datas.length;j++ ){
		      	data[j]={}
		      	data[j].value=datas[j].count/nums;
		      	data[j].key=datas[j].locked==1 ? '在职':'离职';
		      }
	     }
	     console.log('员工',data)
        var Stat = G2.Stat;
        var chart = new G2.Chart({
            id: 'charts_staff',
            forceFit: true,
            plotCfg: {
                margin: [90, 0, 60, 0]
            },
            height: 450,
        });
        chart.source(data);
        // 重要：绘制饼图时，必须声明 theta 坐标系
        chart.coord('theta', {
            radius: 0.7, // 设置饼图的大小
            inner: 0.6
        });
        chart.tooltip({
            title: null
        });
        chart.legend({
            position: 'top', // 设置图例的显示位置
            spacingX: 20,    // 图例项之间的水平间距
            dy:20,
            title: null,     // 不展示图例 title
            word: {
                fill: '#656363',
                fontSize: 14
            }
        });
        chart.intervalStack()
            .shape('burstPie')
            .position(Stat.summary.percent('value'))
            .color('key', ['#46ac49', '#e05949'])
            .style({
                stroke: '#fff',
                lineWidth: 2
            }).label('key*..percent',function(key, percent){
            percent = (percent * 100).toFixed(2) + '%';
            return key + ':' + percent;
        });

        chart.render();
    	}
    	$scope.kongZhiTai($scope.fn)
    	
    	
    	
        /*var data = [
            { value: 0.35, key: '正常' },
            { value: 0.65, key: '离职' },
        ];
        var Stat = G2.Stat;
        var chart = new G2.Chart({
            id: 'charts_staff',
            forceFit: true,
            plotCfg: {
                margin: [90, 0, 60, 0]
            },
            height: 450,
        });
        chart.source(data);
        // 重要：绘制饼图时，必须声明 theta 坐标系
        chart.coord('theta', {
            radius: 0.7, // 设置饼图的大小
            inner: 0.6
        });
        chart.tooltip({
            title: null
        });
        chart.legend({
            position: 'top', // 设置图例的显示位置
            spacingX: 20,    // 图例项之间的水平间距
            dy:20,
            title: null,     // 不展示图例 title
            word: {
                fill: '#656363',
                fontSize: 14
            }
        });
        chart.intervalStack()
            .shape('burstPie')
            .position(Stat.summary.percent('value'))
            .color('key', ['#46ac49', '#e05949'])
            .style({
                stroke: '#fff',
                lineWidth: 2
            }).label('key*..percent',function(key, percent){
            percent = (percent * 100).toFixed(2) + '%';
            return key + ':' + percent;
        });

        chart.render();*/
        // chart.on('plotclick',function(ev){
        //     var data = ev.data;
        //     if (data) {
        //         var value = data._origin['value'];
        //         var name = data._origin['key'];
        //         $('.charts_name').text(name+':'+(value*100).toFixed(2)+'%')
        //     }
        // });
    }
}


chartsStaffCtrl.$inject = ['$scope','$rootScope','$timeout','$location','$interval']
module.exports = angular.module('directive.chartsStaff', []).directive('chartsStaff', function() {
    return {
        restrict: 'E',
        template: tem,
        replace:true,
        controller: chartsStaffCtrl
    }
}).name